﻿//------------------------------------------------------------------------------
// The contents of this file are subject to the Microsoft Public License (Ms-PL)
// You may obtain a copy of the License at http://psadmin.codeplex.com/license. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, 
// WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations 
// under the License.
// 
// The initial developer is Ben Foster (ben.foster@retroviz.com)
// Copyright (c) Retroviz Limited (http://www.retroviz.com).
// All Rights Reserved.
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using log4net;
using PSAdmin.Core.Interfaces;

namespace PSAdmin.Services
{
    public class Log4NetLoggerService : ILoggerService {
        private ILog _logger;
        
        public Log4NetLoggerService() {
            _logger = LogManager.GetLogger(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
        
        public void Info(string message) {
            _logger.Info(message);
        }

        public void Warn(string message) {
            _logger.Warn(message);
        }

        public void Debug(string message) {
            _logger.Debug(message);
        }

        public void Error(string message) {
            _logger.Error(message);
        }

        public void Error(Exception ex) {
            _logger.Error(ex.Message, ex);
        }

        public void Fatal(string message) {
            _logger.Fatal(message);
        }

        public void Fatal(Exception ex) {
            _logger.Fatal(ex.Message, ex);
        }
    }

    public class Log4NetStartUpTask : IStartUpTask
    {
        public bool IsEnabled { get { return true; } }
        
        public void Execute() {
            log4net.Config.XmlConfigurator.Configure(
                new System.IO.FileInfo(
                    HttpContext.Current.Server.MapPath("~/log4net.config")));
        }
    }

}
